package com.itheima.grow.controller;

import com.itheima.grow.mapper.QuestionMapper;
import com.itheima.grow.model.entity.Question;
import com.itheima.grow.model.other.Result;
import com.itheima.grow.model.query.QuestionQuery;
import com.itheima.grow.service.IQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/mapper")
public class QuestionController {

    @Resource
    private QuestionMapper questionMapper;

    @Resource
    private IQuestionService questionService;

    @GetMapping("/testMapper")
    public Result testMapper() {
        Question question = new Question();
        question.setId(1);
        question.setQname("财务问题2");
        question.setQlevel("1");
        boolean b = questionService.saveOrUpdate(question);
        return Result.success(b);
    }


    @GetMapping("/test02")
    public Result test02() {
       return Result.success(questionService.getOne(2l));
    }

    @PostMapping("/test03")
    public Result test03(@RequestBody QuestionQuery query) {
        System.out.println(query.toString());
        Question question = new Question();
        question.setPid(0);
        BeanUtils.copyProperties(query,question);
        return Result.success(questionMapper.insert(question));
    }



}
